/**
 * 功能:对提交的数据进行验证
 *
 *
 *
 * 已继承的任务
 * 当请求为get时,自动验证guid
 */
const Logic = require('../logic');
module.exports = class extends Logic
{

    competitionDescAction()
    {
        return this.checkGetGuid();
    }

    competitionStepAction()
    {
        return this.checkGetGuid();
    }

    getAction()
    {
        return this.checkGetGuid();
    }

    competitionWorksCountAction()
    {
        return this.checkGetGuid();
    }

    postAction()
    {
        let postData=think.stringToJson(this.post('data'));
        if(postData===false){
            return this.fail(52004, '提交的表单信息错误,该数据必须为json格式,请检查数据格式,上传数据格式为{\'data\',yourJsonData},如 : $.post("http://127.0.0.1:8091/apiv1/competition",{\'data\':yourJsonData}),yourJsonData为你要上传的数据包');
        }

        //首先验证大的数据
        let baseRules={
            Title: { type: "string",min:1},
            CoverUrl: { type: "string",min:5},
            Desc: { type: "string",min:1},
            GameShowsType: { type:'string',enum:['本平台发布','第三方页面']},
            GameStartTime: { type: "number"},
            GameEndTime: { type: "number"},
            HeadCount: { type: "number",min:1},
            ApplyNotes: { type: "string",min:1},
            ApplyStartTime: { type: "number",min:1},
            ApplyEndTime: { type: "number",min:1},
            ApplyType: { type: "string",enum:['团队','个人']},
        };
        let vres=think.validate(postData,baseRules);
        if(vres!==true)return this.error(52040,vres[0].message);
        //验证步骤数据

    }

    deleteAction(){
        return this.checkGetGuid();
    }

    competitionStepsWorksCountAndAppCountAction(){
        return this.checkGetGuid();
    }

    getWorksByStepGuidAction(){
        return this.checkGetGuid();
    }

    /**
     * 添加比赛v1 修复第已版本的bug
     * 接受信息验证并分离
     * */
    createCompetitionAction(){

        let postData=think.stringToJson(this.post('data'));
        if(postData===false){
            return this.fail(52004, '提交的表单信息错误,该数据必须为json格式,请检查数据格式,上传数据格式为{\'data\',yourJsonData},如 : $.post("http://127.0.0.1:8091/apiv1/competition",{\'data\':yourJsonData}),yourJsonData为你要上传的数据包');
        }
        //首先验证大的数据
        let baseRules={
            Title: { type: "string",min:1},
            CoverUrl: { type: "string",min:5},
            Desc: { type: "string",min:1},
            GameShowsType: { type:'string',enum:['本平台发布','第三方页面']},
            GameStartTime: { type: "number"},
            GameEndTime: { type: "number"},
            steps:{type:'array'},
            HeadCount: { type: "number",min:1},
            ApplyNotes: { type: "string",min:1},
            ApplyStartTime: { type: "number",min:1},
            ApplyEndTime: { type: "number",min:1},
            ApplyType: { type: "string",enum:['团队','个人']},
        };
        let bbase=think.validate(postData,baseRules);
        if(bbase!==true)return this.error(52040,bbase[0].message);
        this.ctx.state.cpdata=postData;


    }

    /**
     * 进入当前流程
     * @returns {Promise.<void>}
     */
    async entercurrentstAction()
    {
        let postData = think.stringToJson(this.post('data'))
        try{
            let valiRule={
                cpguid: { type: "string",min:36,max:36},
                stguid: { type: "string",min:36,max:36},
            };
            let bbase=think.validate(postData,valiRule);
            if(bbase!==true)return this.error(52040,bbase[0].message);
            this.ctx.state.data=postData;
        }catch (e){
            return this.info(-3);
        }
    }

    async endCurrentCPAction(){
        return this.checkGetGuid();
    }
};